
import java.io.IOException;
import java.util.Random;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;


public class Pelota extends Sprite{

    private int incX;
    private int incY;
    private int anchoPantalla, altoPantalla;
    static Random r = new Random();

    public Pelota(String archivo, int anchoPantalla, int altoPantalla) throws IOException{
        super(Image.createImage(archivo), 20, 20);
        int[] secuencia = {0,0,0,0,0,1,1,1,1,1,2,2,2,2,2};
        super.setFrameSequence(secuencia);
        incX = r.nextInt(4);
        incY = r.nextInt(2);
        this.anchoPantalla = anchoPantalla;
        this.altoPantalla = altoPantalla;
    }

    public void dibujar(Graphics g){
        super.paint(g);
    }

    public void actualizar() {
        super.move(incX, incY);
        if(super.getX()+super.getWidth() > anchoPantalla ){
            incX = -incX;
            super.setPosition(anchoPantalla-super.getWidth(), super.getY());
        }

        if(super.getX() < 0 ){
            incX = -incX;
            super.setPosition(0, super.getY());
        }

        if(super.getY() < 0 ){
            incY = -incY;
            super.setPosition(super.getX(), 0);
        }
        super.nextFrame();

    }

    public void moverArriba() {
        incY = -incY;
    }


}
